import React, {useEffect, useState} from "react";
// import store from "../../store";
import {Button} from "antd";
import {connect, useDispatch} from "react-redux";
import * as actions from '@/store/actions'
/**
* redux使用
* */



// const Dom7 = () => {
//     const {pageNum , oppNum} = store.getState()
//     let [num , setNum] = useState(0)
//     const update = () => {
//         setNum(num++)
//     }
//     const addFn = () => {
//         store.dispatch({type: '111'})
//     }
//     useEffect(()=> {
//        store.subscribe(update)
//     },[num])
//     return <div>
//         <div>{pageNum}</div>
//         <div>{oppNum}</div>
//         <Button onClick={addFn}>点击</Button>
//     </div>
// }

// class  Dom7 extends React.Component{
//     addFn = () => {
//         store.dispatch({type: '111'})
//         this.forceUpdate()
//     }
//     render() {
//         let {pageNum , oppNum} = store.getState()
//         return <div>
//             <div>{pageNum}</div>
//             <div>{oppNum}</div>
//             <Button onClick={this.addFn}>点击</Button>
//         </div>
//     }
//
// }

/**
 * react-redux使用
 * */

// const Dom7 = (props) => {
//     let {pageNum , oppNum,addFn} = props
//     return <div>
//         <div>{pageNum}</div>
//         <div>{oppNum}</div>
//         <Button onClick={addFn}>点击</Button>
//     </div>
// }

class Dom7 extends React.Component{
    render() {
        let {pageNum , oppNum,addFn} = this.props
        return <div>
            <div>{pageNum}</div>
            <div>{oppNum}</div>
            <Button onClick={addFn}>点击</Button>
        </div>
    }

}

function fn () {
   return  new Promise(resolve => {
        setTimeout(() => {
            resolve(12)
        },1000)
    })

}

function mapDispatchToProps(dispatch, ownProps) {
    return {
        addFn: async() => {
            let data = await fn()
            console.log(data)
            dispatch({type: actions.add,data})
        }
    }
}

export default connect(store => store , mapDispatchToProps)(Dom7)
